#include "Method.h"

double func1(double x){
  return 1.0/x;
}

double dfunc1(double x){
  return -1.0/(x*x);
}

double func2(double x){
  return x*x*x-3*x*x-x+3;
}

double dfunc2(double x){
  return 3*x*x-6*x-1;
}

double func3(double x){
  return sin(x);
}

double dfunc3(double x){
  return cos(x);
}

int main(){
  double (*pf1)(double) = &func1;
  double (*pf2)(double) = &func2;
  double (*pf3)(double) = &func3;
  double (*pdf1)(double) = &dfunc1;
  double (*pdf2)(double) = &dfunc2;
  double (*pdf3)(double) = &dfunc3;
  Newton<double> NT(50,0.01,pf1,pdf1,6);
  cout << "init : " << NT.get_init() << ", "
       << "max_iter: " << NT.get_max_iter() << ", "
       << "tol: " << NT.get_tol() << endl
       << "f at 2 = " << (*(NT.get_function()))(2) << endl
       << "df at 2 = " << (*(NT.get_dfunction()))(2) << endl;
  NT.set_init(0.1);
  NT.set_max_iter(100);
  NT.set_tol(1e-4);
  NT.set_function(pf3);
  NT.set_dfunction(pdf3);
  cout << "after: " << endl;
   cout << "init : " << NT.get_init() << ", "
       << "max_iter: " << NT.get_max_iter() << ", "
       << "tol: " << NT.get_tol() << endl
       << "f at 2 = " << (*(NT.get_function()))(2) << endl
       << "df at 2 = " << (*(NT.get_dfunction()))(2) << endl;
   cout << "Newton method with initial 0.1 :" << endl
        << NT.solve() << endl;
   NT.set_init(3);
   cout << "Newton method with initial 3 :" << endl
        << NT.solve() << endl;
  
}

